/**
 *
 */
package com.hp.snap.gr.action.impl;

import com.hp.snap.gr.exception.ActionException;
import com.hp.snap.gr.model.jaxb.ActionType;
import com.hp.snap.gr.model.jaxb.SCPToRemoteActionType;
import com.hp.snap.gr.utils.SSHTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

/**
 * @author chzhenhu
 */
public class SCPToRemoteActionHandler extends AbstractActionHandler {

	/* (non-Javadoc)
     * @see com.hp.snap.gr.action.ActionHandler#execute(com.hp.snap.gr.model.jaxb.ActionType, java.util.Map, java.util.Map)
	 */

    private static Logger logger = LoggerFactory.getLogger(SCPToRemoteActionHandler.class);

    @Override
    public void execute(ActionType action,
                        Map<String, Object> actionPlanInputs,
                        Map<String, Object> actionPlanOutputs) throws ActionException {
        logger.debug("invoke the SCPToRemoteActionHandler");
        SCPToRemoteActionType actionType = (SCPToRemoteActionType) action;
        List<String> localFiles = actionType.getLocal();
        String remotePath = actionType.getRemote();

        try {
            SSHTools ssh = new SSHTools(null, null);
            for (String localFile : localFiles) {
                ssh.copyFromLocal(localFile, actionType.getRemoteHost(), remotePath);
            }

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ActionException(e);
        }
    }

}
